import {Group} from "./Group"

export class GroupDB{
	
	_map = new Map()
	
	master = ''
	
	
	getGroup(id){
		if(!this._map.has(id)){
			const group = Group.creatNullIns({id})
			group.fetchOrigin()
			this.setGroup(group)
		}
		return this._map.get(id)
	}
	
	setGroup(group){
		this._map.set(group.id,group)
	}
	
	delGroup(id){
		this._map.delete(id)
	}
	
	getGroups(ids){
		const groups = ids.map((id)=>{
			return this.getGroup(id)
		})
		return groups
	}
	
	setGroups(groups){
		groups.forEach((group)=>{
			return this.setGroup(group)
		})
	}
	
	delGroups(ids){
		ids.map((id)=>{
			return this.delGroup(id)
		})
	}
	
	clear(){
		this._map.clear()
	}
	
	setMaster(userId){
		this.master = userId
	}
}